package com.ktgj.flight.controller;

import java.math.BigDecimal;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.FlightCountry;
import com.ktgj.flight.service.IFlightCountryService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 系统字典_国家Controller
 * 
 * @author ruoyi
 * @date 2022-06-01
 */
@RestController
@RequestMapping("/country")
public class FlightCountryController extends BaseController
{
    @Autowired
    private IFlightCountryService flightCountryService;

    /**
     * 查询系统字典_国家列表
     */
    @PreAuthorize(hasPermi = "flight:country:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightCountry flightCountry)
    {
        startPage();
        List<FlightCountry> list = flightCountryService.selectFlightCountryList(flightCountry);
        return getDataTable(list);
    }

    /**
     * 国家列表
     * @return
     */
    @PostMapping("/country")
    public AjaxResult country() {
        List<FlightCountry> flightCountries = flightCountryService.selectFlightCountryList(null);
        return AjaxResult.success(flightCountries);
    }

    /**
     * 导出系统字典_国家列表
     */
    @PreAuthorize(hasPermi = "flight:country:export")
    @Log(title = "系统字典_国家", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlightCountry flightCountry) throws IOException
    {
        List<FlightCountry> list = flightCountryService.selectFlightCountryList(flightCountry);
        ExcelUtil<FlightCountry> util = new ExcelUtil<FlightCountry>(FlightCountry.class);
        util.exportExcel(response, list, "系统字典_国家数据");
    }

    /**
     * 获取系统字典_国家详细信息
     */
    @PreAuthorize(hasPermi = "flight:country:query")
    @GetMapping(value = "/{countryId}")
    public AjaxResult getInfo(@PathVariable("countryId") BigDecimal countryId)
    {
        return AjaxResult.success(flightCountryService.selectFlightCountryById(countryId));
    }

    /**
     * 新增系统字典_国家
     */
    @PreAuthorize(hasPermi = "flight:country:add")
    @Log(title = "系统字典_国家", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlightCountry flightCountry)
    {
        return toAjax(flightCountryService.insertFlightCountry(flightCountry));
    }

    /**
     * 修改系统字典_国家
     */
    @PreAuthorize(hasPermi = "flight:country:edit")
    @Log(title = "系统字典_国家", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlightCountry flightCountry)
    {
        return toAjax(flightCountryService.updateFlightCountry(flightCountry));
    }

    /**
     * 删除系统字典_国家
     */
    @PreAuthorize(hasPermi = "flight:country:remove")
    @Log(title = "系统字典_国家", businessType = BusinessType.DELETE)
	@DeleteMapping("/{countryIds}")
    public AjaxResult remove(@PathVariable BigDecimal[] countryIds)
    {
        return toAjax(flightCountryService.deleteFlightCountryByIds(countryIds));
    }
}
